from api.ihrm_Login import IhrmLogin
from common.assertTools import common_assert


class TestIhrmLogin(object):
    def setup_class(self):#类之前自动被调用一次 执行
        # 创建实例
        self.ihrm_login = IhrmLogin()

    def test1_login_success(self):  # 登录成功
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "123456"}
        resp = self.ihrm_login.login(json_data)
        print("登陆结果为:", resp.json())
        # 调用断言
        common_assert(resp,200,True,10000,"操作成功")

    def test2_mobile_notregister(self):  # 手机号未注册
        # 使用实例调用登录
        json_data = {"mobile": "13823200002", "password": "123456"}
        resp = self.ihrm_login.login(json_data)
        print("手机号未注册:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")

    def test3_pwd_err(self):  # 密码错误
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "1234567"}
        resp = self.ihrm_login.login(json_data)
        print("密码错误:", resp.json())
        # 调用断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")
    def test4_10_mobile(self):  # 10位手机号
        # 使用实例调用登录
        json_data = {"mobile": "1380000000", "password": "1234567"}
        resp = self.ihrm_login.login(json_data)
        print("10位手机号:", resp.json())
        # 调用断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")
    def test5_12_mobile(self):# 12位手机号
        # 使用实例调用登录
        json_data = {"mobile": "138000000012", "password": "1234567"}
        resp = self.ihrm_login.login(json_data)
        print("12位手机号:", resp.json())
        # 调用断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")

    def test6_null_mobile(self):  # 手机号为空
        # 使用实例调用登录
        json_data = {"mobile": None, "password": "1234567"}
        resp = self.ihrm_login.login(json_data)
        print("手机号为空:", resp.json())
        # 调用断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")
    def test7_character_mobile(self):  # 含有字母,特殊字符的11位手机号
        # 使用实例调用登录
        json_data = {"mobile": "138a32000@#", "password": "123456"}
        resp = self.ihrm_login.login(json_data)
        print("特殊字符的11位手机号:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")
    def test8_1_pwd(self):  # 1位密码
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "1"}
        resp = self.ihrm_login.login(json_data)
        print("1位密码:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")
    def test9_100_pwd(self):  # 100位密码
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "12345678901234567890123456789012345678901234567890123456789012345678901234567890"}
        resp = self.ihrm_login.login(json_data)
        print("100位密码:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")

    def test10_null_pwd(self):  # 密码为空
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": None}
        resp = self.ihrm_login.login(json_data)
        print("密码为空:", resp.json())
        # 调用断言
        common_assert(resp, 200, False, 20001, "用户名或密码错误")
    def test11_character_pwd(self):  # 含有字母,特殊字符的密码
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "1aw34@"}
        resp = self.ihrm_login.login(json_data)
        print("特殊字符的密码:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")
    def test12_many_params(self):  # 多参"abc":"123"
        # 使用实例调用登录
        json_data = {"mobile": "13800000002", "password": "123456","abc":"123"}
        resp = self.ihrm_login.login(json_data)
        print("多参:", resp.json())
        # 调用断言
        common_assert(resp,200,True,10000,"操作成功")
    def test13_less_params(self):  # 少参mobile
        # 使用实例调用登录
        json_data = {"mobile": "13800000002"}
        resp = self.ihrm_login.login(json_data)
        print("少参:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")
    def test14_err_params(self):  # 错误参数password为pwd
        # 使用实例调用登录
        json_data = {"mobile": "13800000002","pwd": "123456"}
        resp = self.ihrm_login.login(json_data)
        print("错误参数:", resp.json())
        # 调用断言
        common_assert(resp,200,False,20001, "用户名或密码错误")

    def test15_no_params(self):  # 无参
        # 使用实例调用登录
        json_data = None
        resp = self.ihrm_login.login(json_data)
        print("无参:", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert False == resp.json().get("success")
        assert 99999 == resp.json().get("code")
        assert "抱歉，系统繁忙，请稍后重试" in resp.json().get("message")
